<template>
    <div class="body_background" :style="GetWindowBackground">
        <div class="body_background">
            <!--搜索框-->
            <div class="search-box">
                <div class="search-input-box">
                    <img src="../../assets/img/search.png" class="search-img">
                    <input class="keyword main-color" placeholder="请输入关键词" v-model="keyword">
                </div>
                <mt-button class="background white-color" size="small" @click="getKeywordFun">搜索</mt-button>
            </div>
            <div class="block-box items-start order-list-box">
                <div class="big-font-size three-color">商品列表</div>
                <div class="order-list-item">
                    <div class="order-content-box" v-for="(item,index) in goodsList" :key="item.id"
                         @click="choseGoodsFun(item,index)"
                    >
                        <div class="big-small-circular" :class="item.choseFlag==true?'background':''">
                            <div class="small-circular" v-if="item.choseFlag==true"></div>
                        </div>
                        <img :src="item.imgUrl"/>
                        <div class="order-info-box">
                            <div class="main-color big-font-size">{{item.title}}</div>
                            <div class="goods-content">
                                <div>
                                    <div class="three-color small-font-size">分类：蔬菜</div>
                                    <div class="three-color small-font-size">规格：200g</div>
                                    <div class="three-color small-font-size">库存：200袋</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="seize-seat light-color">-- 没有数据了 --</div>
        </div>
        <div class="body_background create-button-box">
            <mt-button class="width40 middle-font-size"
                       @click="cancelClickFun"
            >取消
            </mt-button>
            <mt-button class="width40 middle-font-size background white-color"
                       @click="submitFun"
            >提交
            </mt-button>
        </div>
    </div>
</template>

<script>
    import {Toast} from 'mint-ui';
    // import '../../../public/js/jquery-1.7.2.min'
    // import '../../assets/js/lin_search.js'

    export default {
        name: "AddGoodsView",
        data() {
            return {
                GetWindowBackground: {
                    'min-height': ''
                },
                keyword: '',
                type: '',//1:出库  2:盘点
                goodsList: [],
            }
        },
        methods: {
            //重新整合商品数据
            getNewGoodsList() {
                var list = [
                    {
                        id: 1,
                        title: "1秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }, {
                        id: 2,
                        title: "2秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }
                    , {
                        id: 3,
                        title: "3秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }
                    , {
                        id: 4,
                        title: "4秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }
                    , {
                        id: 5,
                        title: "5秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }
                    , {
                        id: 6,
                        title: "6秘制小番茄500g",
                        spec: '500g/袋',
                        weight: '500g',
                        warehouse: '常温',
                        imgUrl:
                            "https://t00img-c.yangkeduo.com/goods/images/2020-08-13/ce99a1b2f665ba478d9573c314686c5d.jpeg"
                    }
                ];
                for (var i = 0; i < list.length; i++) {
                    var item = list[i]
                    item['choseFlag'] = false;
                }
                this.goodsList = list
            },
            //筛选
            getKeywordFun() {
                var keyword = this.keyword;
                console.log(keyword)
            },
            //选商品
            choseGoodsFun(item) {
                item.choseFlag = !item.choseFlag
            },
            //取消
            cancelClickFun() {
                var url = '';
                if (this.type == 1) {
                    url = '/AddDeliveryGoods'
                } else if (this.type == 2) {
                    url = '/StockInventoryCreate'
                }
                this.$router.push(url)
            },
            //提交
            submitFun() {
                var url = '';
                var list = this.goodsList;
                var array = [];//选中的数据
                var localS_name = '', 缓存的名字
                for (var i = 0; i < list.length; i++) {
                    var item = list[i];
                    if (item.choseFlag) {
                        array.push(item)
                    }
                }
                // console.log(array)
                if (this.type == 1) {
                    localS_name = 'add_delivery_goods';
                    url = '/AddDeliveryGoods'
                } else if (this.type == 2) {
                    localS_name = 'add_inventory_goods';
                    url = '/StockInventoryCreate'
                }
                localStorage.setItem(localS_name, JSON.stringify(array))
                this.$router.push(url)
            },

            getHeight() {
                // 获取浏览器高度
                this.GetWindowBackground['min-height'] = window.innerHeight + 'px'
            },
        },
        mounted() { //自动加载
            this.getNewGoodsList()
            this.type = this.$route.query.type;
            console.log(this.type)
        },
        // 生命周期 - 创建完成（可以访问当前this实例）
        created() {
            window.addEventListener('resize', this.getHeight) // 注册监听器
            this.getHeight() // 页面创建时先调用一次
        },
        // 生命周期 - 销毁完成
        destroyed() {
            window.removeEventListener('resize', this.getHeight)
        },
    }
</script>

<style lang="scss" scoped>
    .search-box {
        width: 80%;
        height: 35px;
        background: #fff;
        padding: 15px 10% !important;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .search-input-box {
            width: 80%;
            height: 35px;
            border-radius: 6px;
            background: #f8f7fc;
            display: flex;
            justify-content: flex-start;
            align-items: center;
        }
        .search-img {
            width: 16px;
            height: 16px;
            margin-left: 20px;
        }
        .keyword {
            font-size: 14px;
            padding: 5px 10px;
            background: transparent;
            border: none;
            outline: none;
            list-style: none;
        }

    }

    .create-box {
        width: 100%;
        padding-bottom: 20px;
        margin-top: 5px;
        li {
            width: 100%;
            height: 45px;
            display: flex;
            align-items: flex-end;
            justify-content: space-between;
            div {
                margin-bottom: 7px;
            }
            input, select {
                width: calc(100% - 100px);
                height: 30px;
                border-top: 0;
                border-left: 0;
                border-right: 0;
                border-bottom: 1px solid #ebedf1;
                outline: none;
                list-style: none;
            }
        }
    }

    .add-inventory-box {
        width: 70%;
        height: 40px;
        line-height: 40px;
        background: #fff;
        border-radius: 6px;
        margin: auto;
        font-size: 14px;
        .padding-left {
            padding-left: 15px;
        }
    }

    .order-list-box {
        margin: 10px auto;
        .order-list-item {
            width: 100%;
            background: #fff;
            margin-top: 10px;
            border-radius: 4px;
            .order-top-box {
                width: 100%;
                height: 35px;
                display: flex;
                justify-content: space-between;
                align-items: center;
            }
            .order-content-box {
                width: 100%;
                display: flex;
                align-items: center;
                padding: 7px 0;
                img {
                    width: 65px;
                    height: 65px;
                    margin-right: 10px;
                    border-radius: 4px;
                }
                .goods-content {
                    width: 100%;
                    display: flex;
                    justify-content: space-between;
                }
                .order-info-box {
                    width: calc(100% - 110px);
                    position: relative;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    text-align: left;
                }
                .goods-count {
                    margin-left: auto;
                    margin-top: 5px;
                }
            }
            .big-small-circular {
                width: 17px;
                height: 17px;
                border-radius: 50%;
                border: 1px solid #05c569;
                display: flex;
                justify-content: center;
                align-items: center;
                margin-right: 10px;
                .small-circular {
                    width: 7px;
                    height: 7px;
                    border-radius: 50%;
                    background: #fff;
                }
            }
        }
    }

    .create-button-box {
        width: 100%;
        height: 70px;
        position: fixed;
        bottom: 0px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        .width40 {
            width: 40%;
            border: 1px solid #05c569;
            color: #05c569;
            border-radius: 10px;
        }
    }

</style>